package org.apache.commons.httpclient;

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.httpclient.auth.AuthChallengeException;
import org.apache.commons.httpclient.auth.AuthChallengeParser;
import org.apache.commons.httpclient.auth.AuthChallengeProcessor;
import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.auth.AuthState;
import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.auth.CredentialsNotAvailableException;
import org.apache.commons.httpclient.auth.CredentialsProvider;
import org.apache.commons.httpclient.auth.MalformedChallengeException;
import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionParams;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

class HttpMethodDirector
{
  private static final Log LOG;
  public static final String PROXY_AUTH_CHALLENGE = "Proxy-Authenticate";
  public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
  public static final String WWW_AUTH_CHALLENGE = "WWW-Authenticate";
  public static final String WWW_AUTH_RESP = "Authorization";
  static Class class$org$apache$commons$httpclient$HttpMethodDirector;
  private AuthChallengeProcessor authProcessor = null;
  private HttpConnection conn;
  private ConnectMethod connectMethod;
  private HttpConnectionManager connectionManager;
  private HostConfiguration hostConfiguration;
  private HttpClientParams params;
  private Set redirectLocations = null;
  private boolean releaseConnection = false;
  private HttpState state;

  static
  {
    Class localClass;
    if (class$org$apache$commons$httpclient$HttpMethodDirector == null)
    {
      localClass = class$("org.apache.commons.httpclient.HttpMethodDirector");
      class$org$apache$commons$httpclient$HttpMethodDirector = localClass;
    }
    while (true)
    {
      LOG = LogFactory.getLog(localClass);
      return;
      localClass = class$org$apache$commons$httpclient$HttpMethodDirector;
    }
  }

  public HttpMethodDirector(HttpConnectionManager paramHttpConnectionManager, HostConfiguration paramHostConfiguration, HttpClientParams paramHttpClientParams, HttpState paramHttpState)
  {
    this.connectionManager = paramHttpConnectionManager;
    this.hostConfiguration = paramHostConfiguration;
    this.params = paramHttpClientParams;
    this.state = paramHttpState;
    this.authProcessor = new AuthChallengeProcessor(this.params);
  }

  private void applyConnectionParams(HttpMethod paramHttpMethod)
    throws IOException
  {
    int i = 0;
    Object localObject = paramHttpMethod.getParams().getParameter("http.socket.timeout");
    if (localObject == null)
      localObject = this.conn.getParams().getParameter("http.socket.timeout");
    if (localObject != null)
      i = ((Integer)localObject).intValue();
    this.conn.setSocketTimeout(i);
  }

  private void authenticate(HttpMethod paramHttpMethod)
  {
    try
    {
      if ((this.conn.isProxied()) && (!(this.conn.isSecure())))
        authenticateProxy(paramHttpMethod);
      authenticateHost(paramHttpMethod);
      return;
    }
    catch (AuthenticationException localAuthenticationException)
    {
      LOG.error(localAuthenticationException.getMessage(), localAuthenticationException);
    }
  }

  private void authenticateHost(HttpMethod paramHttpMethod)
    throws AuthenticationException
  {
    if (!(cleanAuthHeaders(paramHttpMethod, "Authorization")));
    while (true)
    {
      return;
      AuthState localAuthState = paramHttpMethod.getHostAuthState();
      AuthScheme localAuthScheme = localAuthState.getAuthScheme();
      if ((localAuthScheme == null) || ((!(localAuthState.isAuthRequested())) && (localAuthScheme.isConnectionBased())))
        continue;
      String str1 = paramHttpMethod.getParams().getVirtualHost();
      if (str1 == null)
        str1 = this.conn.getHost();
      AuthScope localAuthScope = new AuthScope(str1, this.conn.getPort(), localAuthScheme.getRealm(), localAuthScheme.getSchemeName());
      if (LOG.isDebugEnabled())
        LOG.debug("Authenticating with " + localAuthScope);
      Credentials localCredentials = this.state.getCredentials(localAuthScope);
      if (localCredentials != null)
      {
        String str2 = localAuthScheme.authenticate(localCredentials, paramHttpMethod);
        if (str2 == null)
          continue;
        paramHttpMethod.addRequestHeader(new Header("Authorization", str2, true));
      }
      if (!(LOG.isWarnEnabled()))
        continue;
      LOG.warn("Required credentials not available for " + localAuthScope);
      if (!(paramHttpMethod.getHostAuthState().isPreemptive()))
        continue;
      LOG.warn("Preemptive authentication requested but no default credentials available");
    }
  }

  private void authenticateProxy(HttpMethod paramHttpMethod)
    throws AuthenticationException
  {
    if (!(cleanAuthHeaders(paramHttpMethod, "Proxy-Authorization")));
    while (true)
    {
      return;
      AuthState localAuthState = paramHttpMethod.getProxyAuthState();
      AuthScheme localAuthScheme = localAuthState.getAuthScheme();
      if ((localAuthScheme == null) || ((!(localAuthState.isAuthRequested())) && (localAuthScheme.isConnectionBased())))
        continue;
      AuthScope localAuthScope = new AuthScope(this.conn.getProxyHost(), this.conn.getProxyPort(), localAuthScheme.getRealm(), localAuthScheme.getSchemeName());
      if (LOG.isDebugEnabled())
        LOG.debug("Authenticating with " + localAuthScope);
      Credentials localCredentials = this.state.getProxyCredentials(localAuthScope);
      if (localCredentials != null)
      {
        String str = localAuthScheme.authenticate(localCredentials, paramHttpMethod);
        if (str == null)
          continue;
        paramHttpMethod.addRequestHeader(new Header("Proxy-Authorization", str, true));
      }
      if (!(LOG.isWarnEnabled()))
        continue;
      LOG.warn("Required proxy credentials not available for " + localAuthScope);
      if (!(paramHttpMethod.getProxyAuthState().isPreemptive()))
        continue;
      LOG.warn("Preemptive authentication requested but no default proxy credentials available");
    }
  }

  static Class class$(String paramString)
  {
    try
    {
      Class localClass = Class.forName(paramString);
      return localClass;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      throw new NoClassDefFoundError(localClassNotFoundException.getMessage());
    }
  }

  private boolean cleanAuthHeaders(HttpMethod paramHttpMethod, String paramString)
  {
    Header[] arrayOfHeader = paramHttpMethod.getRequestHeaders(paramString);
    int i = 1;
    int j = 0;
    if (j < arrayOfHeader.length)
    {
      label14: Header localHeader = arrayOfHeader[j];
      if (localHeader.isAutogenerated())
        paramHttpMethod.removeRequestHeader(localHeader);
      while (true)
      {
        ++j;
        break label14:
        i = 0;
      }
    }
    return i;
  }

  private boolean executeConnect()
    throws IOException, HttpException
  {
    this.connectMethod = new ConnectMethod(this.hostConfiguration);
    this.connectMethod.getParams().setDefaults(this.hostConfiguration.getParams());
    if (!(this.conn.isOpen()))
      label32: this.conn.open();
    if ((this.params.isAuthenticationPreemptive()) || (this.state.isAuthenticationPreemptive()))
    {
      LOG.debug("Preemptively sending default basic credentials");
      this.connectMethod.getProxyAuthState().setPreemptive();
      this.connectMethod.getProxyAuthState().setAuthAttempted(true);
    }
    while (true)
    {
      label109: boolean bool;
      try
      {
        authenticateProxy(this.connectMethod);
        applyConnectionParams(this.connectMethod);
        this.connectMethod.execute(this.state, this.conn);
        int i = this.connectMethod.getStatusCode();
        int j = 0;
        AuthState localAuthState = this.connectMethod.getProxyAuthState();
        if (i != 407)
          break label246;
        bool = true;
        localAuthState.setAuthRequested(bool);
        if ((localAuthState.isAuthRequested()) && (processAuthenticationResponse(this.connectMethod)))
          j = 1;
        if (j != 0)
          break label252;
        if ((i < 200) || (i >= 300))
          break label275;
        this.conn.tunnelCreated();
        this.connectMethod = null;
        k = 1;
        label246: return k;
      }
      catch (AuthenticationException localAuthenticationException)
      {
        LOG.error(localAuthenticationException.getMessage(), localAuthenticationException);
        break label109:
        bool = false;
      }
      label252: if (this.connectMethod.getResponseBodyAsStream() != null);
      this.connectMethod.getResponseBodyAsStream().close();
      break label32:
      label275: this.conn.close();
      int k = 0;
    }
  }

  private void executeWithRetry(HttpMethod paramHttpMethod)
    throws IOException, HttpException
  {
    int i = 0;
    while (true)
    {
      ++i;
      try
      {
        if (LOG.isTraceEnabled())
          LOG.trace("Attempt number " + i + " to process request");
        if (this.conn.getParams().isStaleCheckingEnabled())
          this.conn.closeIfStale();
        if (!(this.conn.isOpen()))
        {
          this.conn.open();
          if ((this.conn.isProxied()) && (this.conn.isSecure()) && (!(paramHttpMethod instanceof ConnectMethod)) && (!(executeConnect())))
            return;
        }
        applyConnectionParams(paramHttpMethod);
        paramHttpMethod.execute(this.state, this.conn);
      }
      catch (HttpException localHttpException)
      {
        try
        {
          throw localHttpException;
        }
        catch (IOException localIOException2)
        {
          if (this.conn.isOpen())
          {
            LOG.debug("Closing the connection.");
            this.conn.close();
          }
          this.releaseConnection = true;
          throw localIOException2;
        }
      }
      catch (IOException localIOException1)
      {
        LOG.debug("Closing the connection.");
        this.conn.close();
        if (!(paramHttpMethod instanceof HttpMethodBase))
          break label316;
        MethodRetryHandler localMethodRetryHandler = ((HttpMethodBase)paramHttpMethod).getMethodRetryHandler();
        if ((localMethodRetryHandler == null) || (localMethodRetryHandler.retryMethod(paramHttpMethod, this.conn, new HttpRecoverableException(localIOException1.getMessage()), i, paramHttpMethod.isRequestSent())))
          break label316;
        LOG.debug("Method retry handler returned false. Automatic recovery will not be attempted");
        throw localIOException1;
      }
      catch (RuntimeException localRuntimeException)
      {
        if (this.conn.isOpen())
        {
          LOG.debug("Closing the connection.");
          this.conn.close();
        }
        this.releaseConnection = true;
        throw localRuntimeException;
      }
      label316: Object localObject = (HttpMethodRetryHandler)paramHttpMethod.getParams().getParameter("http.method.retry-handler");
      if (localObject == null)
        localObject = new DefaultHttpMethodRetryHandler();
      if (!(((HttpMethodRetryHandler)localObject).retryMethod(paramHttpMethod, localIOException1, i)))
      {
        LOG.debug("Method retry handler returned false. Automatic recovery will not be attempted");
        throw localIOException1;
      }
      if (LOG.isInfoEnabled())
        LOG.info("I/O exception (" + localIOException1.getClass().getName() + ") caught when processing request: " + localIOException1.getMessage());
      if (LOG.isDebugEnabled())
        LOG.debug(localIOException1.getMessage(), localIOException1);
      LOG.info("Retrying request");
    }
  }

  private void fakeResponse(HttpMethod paramHttpMethod)
    throws IOException, HttpException
  {
    LOG.debug("CONNECT failed, fake the response for the original method");
    if (paramHttpMethod instanceof HttpMethodBase)
    {
      ((HttpMethodBase)paramHttpMethod).fakeResponse(this.connectMethod.getStatusLine(), this.connectMethod.getResponseHeaderGroup(), this.connectMethod.getResponseBodyAsStream());
      paramHttpMethod.getProxyAuthState().setAuthScheme(this.connectMethod.getProxyAuthState().getAuthScheme());
      this.connectMethod = null;
    }
    while (true)
    {
      return;
      this.releaseConnection = true;
      LOG.warn("Unable to fake response on method as it is not derived from HttpMethodBase.");
    }
  }

  private boolean isAuthenticationNeeded(HttpMethod paramHttpMethod)
  {
    AuthState localAuthState1 = paramHttpMethod.getHostAuthState();
    boolean bool1;
    label21: boolean bool2;
    if (paramHttpMethod.getStatusCode() == 401)
    {
      bool1 = true;
      localAuthState1.setAuthRequested(bool1);
      AuthState localAuthState2 = paramHttpMethod.getProxyAuthState();
      if (paramHttpMethod.getStatusCode() != 407)
        break label111;
      bool2 = true;
      label49: localAuthState2.setAuthRequested(bool2);
      if ((!(paramHttpMethod.getHostAuthState().isAuthRequested())) && (!(paramHttpMethod.getProxyAuthState().isAuthRequested())))
        break label134;
      LOG.debug("Authorization required");
      if (!(paramHttpMethod.getDoAuthentication()))
        break label117;
    }
    label134: for (int i = 1; ; i = 0)
      while (true)
      {
        return i;
        bool1 = false;
        break label21:
        label111: bool2 = false;
        break label49:
        label117: LOG.info("Authentication requested but doAuthentication is disabled");
        i = 0;
      }
  }

  private boolean isRedirectNeeded(HttpMethod paramHttpMethod)
  {
    switch (paramHttpMethod.getStatusCode())
    {
    case 304:
    case 305:
    case 306:
    default:
    case 301:
    case 302:
    case 303:
    case 307:
    }
    for (int i = 0; ; i = 0)
      while (true)
      {
        return i;
        LOG.debug("Redirect required");
        if (!(paramHttpMethod.getFollowRedirects()))
          break;
        i = 1;
      }
  }

  private boolean processAuthenticationResponse(HttpMethod paramHttpMethod)
  {
    LOG.trace("enter HttpMethodBase.processAuthenticationResponse(HttpState, HttpConnection)");
    try
    {
      switch (paramHttpMethod.getStatusCode())
      {
      case 401:
        bool1 = processWWWAuthChallenge(paramHttpMethod);
        break;
      case 407:
        boolean bool2 = processProxyAuthChallenge(paramHttpMethod);
        bool1 = bool2;
      }
    }
    catch (Exception localException)
    {
      if (LOG.isErrorEnabled())
        LOG.error(localException.getMessage(), localException);
      bool1 = false;
    }
    boolean bool1 = false;
    return bool1;
  }

  private boolean processProxyAuthChallenge(HttpMethod paramHttpMethod)
    throws MalformedChallengeException, AuthenticationException
  {
    AuthState localAuthState = paramHttpMethod.getProxyAuthState();
    Map localMap = AuthChallengeParser.parseChallenges(paramHttpMethod.getResponseHeaders("Proxy-Authenticate"));
    int i;
    if (localMap.isEmpty())
    {
      LOG.debug("Proxy authentication challenge(s) not found");
      i = 0;
    }
    while (true)
    {
      return i;
      Object localObject = null;
      try
      {
        AuthScheme localAuthScheme = this.authProcessor.processChallenge(localAuthState, localMap);
        localObject = localAuthScheme;
        label63: if (localObject != null)
          break label103;
        label103: i = 0;
      }
      catch (AuthChallengeException localAuthChallengeException)
      {
        if (LOG.isWarnEnabled());
        LOG.warn(localAuthChallengeException.getMessage());
        break label63:
        AuthScope localAuthScope = new AuthScope(this.conn.getProxyHost(), this.conn.getProxyPort(), localObject.getRealm(), localObject.getSchemeName());
        if (LOG.isDebugEnabled())
          LOG.debug("Proxy authentication scope: " + localAuthScope);
        if ((localAuthState.isAuthAttempted()) && (localObject.isComplete()))
        {
          if (promptForProxyCredentials(localObject, paramHttpMethod.getParams(), localAuthScope) == null)
          {
            if (LOG.isInfoEnabled())
              LOG.info("Failure authenticating with " + localAuthScope);
            i = 0;
          }
          i = 1;
        }
        localAuthState.setAuthAttempted(true);
        Credentials localCredentials = this.state.getProxyCredentials(localAuthScope);
        if (localCredentials == null)
          localCredentials = promptForProxyCredentials(localObject, paramHttpMethod.getParams(), localAuthScope);
        if (localCredentials == null)
        {
          if (LOG.isInfoEnabled())
            LOG.info("No credentials available for " + localAuthScope);
          i = 0;
        }
        i = 1;
      }
    }
  }

  // ERROR //
  private boolean processRedirectResponse(HttpMethod paramHttpMethod)
    throws RedirectException
  {
    // Byte code:
    //   0: aload_1
    //   1: ldc_w 524
    //   4: invokeinterface 528 2 0
    //   9: astore_2
    //   10: aload_2
    //   11: ifnonnull +48 -> 59
    //   14: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   17: new 191	java/lang/StringBuffer
    //   20: dup
    //   21: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   24: ldc_w 530
    //   27: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   30: aload_1
    //   31: invokeinterface 449 1 0
    //   36: invokevirtual 359	java/lang/StringBuffer:append	(I)Ljava/lang/StringBuffer;
    //   39: ldc_w 532
    //   42: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   45: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   48: invokeinterface 534 2 0
    //   53: iconst_0
    //   54: istore 10
    //   56: iload 10
    //   58: ireturn
    //   59: aload_2
    //   60: invokevirtual 537	org/apache/commons/httpclient/Header:getValue	()Ljava/lang/String;
    //   63: astore_3
    //   64: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   67: invokeinterface 189 1 0
    //   72: ifeq +37 -> 109
    //   75: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   78: new 191	java/lang/StringBuffer
    //   81: dup
    //   82: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   85: ldc_w 539
    //   88: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   91: aload_3
    //   92: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   95: ldc_w 541
    //   98: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   101: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   104: invokeinterface 208 2 0
    //   109: new 543	org/apache/commons/httpclient/URI
    //   112: dup
    //   113: aload_0
    //   114: getfield 100	org/apache/commons/httpclient/HttpMethodDirector:conn	Lorg/apache/commons/httpclient/HttpConnection;
    //   117: invokevirtual 547	org/apache/commons/httpclient/HttpConnection:getProtocol	()Lorg/apache/commons/httpclient/protocol/Protocol;
    //   120: invokevirtual 552	org/apache/commons/httpclient/protocol/Protocol:getScheme	()Ljava/lang/String;
    //   123: aconst_null
    //   124: aload_0
    //   125: getfield 100	org/apache/commons/httpclient/HttpMethodDirector:conn	Lorg/apache/commons/httpclient/HttpConnection;
    //   128: invokevirtual 172	org/apache/commons/httpclient/HttpConnection:getHost	()Ljava/lang/String;
    //   131: aload_0
    //   132: getfield 100	org/apache/commons/httpclient/HttpMethodDirector:conn	Lorg/apache/commons/httpclient/HttpConnection;
    //   135: invokevirtual 177	org/apache/commons/httpclient/HttpConnection:getPort	()I
    //   138: aload_1
    //   139: invokeinterface 555 1 0
    //   144: invokespecial 558	org/apache/commons/httpclient/URI:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ILjava/lang/String;)V
    //   147: astore 4
    //   149: new 543	org/apache/commons/httpclient/URI
    //   152: dup
    //   153: aload_3
    //   154: iconst_1
    //   155: aload_1
    //   156: invokeinterface 90 1 0
    //   161: invokevirtual 561	org/apache/commons/httpclient/params/HttpMethodParams:getUriCharset	()Ljava/lang/String;
    //   164: invokespecial 564	org/apache/commons/httpclient/URI:<init>	(Ljava/lang/String;ZLjava/lang/String;)V
    //   167: astore 5
    //   169: aload 5
    //   171: invokevirtual 567	org/apache/commons/httpclient/URI:isRelativeURI	()Z
    //   174: ifeq +203 -> 377
    //   177: aload_0
    //   178: getfield 73	org/apache/commons/httpclient/HttpMethodDirector:params	Lorg/apache/commons/httpclient/params/HttpClientParams;
    //   181: ldc_w 569
    //   184: invokevirtual 573	org/apache/commons/httpclient/params/HttpClientParams:isParameterTrue	(Ljava/lang/String;)Z
    //   187: ifeq +43 -> 230
    //   190: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   193: new 191	java/lang/StringBuffer
    //   196: dup
    //   197: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   200: ldc_w 575
    //   203: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   206: aload_3
    //   207: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   210: ldc_w 577
    //   213: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   216: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   219: invokeinterface 234 2 0
    //   224: iconst_0
    //   225: istore 10
    //   227: goto -171 -> 56
    //   230: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   233: ldc_w 579
    //   236: invokeinterface 208 2 0
    //   241: new 543	org/apache/commons/httpclient/URI
    //   244: dup
    //   245: aload 4
    //   247: aload 5
    //   249: invokespecial 582	org/apache/commons/httpclient/URI:<init>	(Lorg/apache/commons/httpclient/URI;Lorg/apache/commons/httpclient/URI;)V
    //   252: astore 8
    //   254: aload_1
    //   255: aload 8
    //   257: invokeinterface 586 2 0
    //   262: aload_0
    //   263: getfield 71	org/apache/commons/httpclient/HttpMethodDirector:hostConfiguration	Lorg/apache/commons/httpclient/HostConfiguration;
    //   266: aload 8
    //   268: invokevirtual 589	org/apache/commons/httpclient/HostConfiguration:setHost	(Lorg/apache/commons/httpclient/URI;)V
    //   271: aload_0
    //   272: getfield 73	org/apache/commons/httpclient/HttpMethodDirector:params	Lorg/apache/commons/httpclient/params/HttpClientParams;
    //   275: ldc_w 591
    //   278: invokevirtual 594	org/apache/commons/httpclient/params/HttpClientParams:isParameterFalse	(Ljava/lang/String;)Z
    //   281: ifeq +161 -> 442
    //   284: aload_0
    //   285: getfield 67	org/apache/commons/httpclient/HttpMethodDirector:redirectLocations	Ljava/util/Set;
    //   288: ifnonnull +14 -> 302
    //   291: aload_0
    //   292: new 596	java/util/HashSet
    //   295: dup
    //   296: invokespecial 597	java/util/HashSet:<init>	()V
    //   299: putfield 67	org/apache/commons/httpclient/HttpMethodDirector:redirectLocations	Ljava/util/Set;
    //   302: aload_0
    //   303: getfield 67	org/apache/commons/httpclient/HttpMethodDirector:redirectLocations	Ljava/util/Set;
    //   306: aload 4
    //   308: invokeinterface 603 2 0
    //   313: pop
    //   314: aload 8
    //   316: invokevirtual 606	org/apache/commons/httpclient/URI:hasQuery	()Z
    //   319: ifeq +9 -> 328
    //   322: aload 8
    //   324: aconst_null
    //   325: invokevirtual 609	org/apache/commons/httpclient/URI:setQuery	(Ljava/lang/String;)V
    //   328: aload_0
    //   329: getfield 67	org/apache/commons/httpclient/HttpMethodDirector:redirectLocations	Ljava/util/Set;
    //   332: aload 8
    //   334: invokeinterface 612 2 0
    //   339: ifeq +103 -> 442
    //   342: new 614	org/apache/commons/httpclient/CircularRedirectException
    //   345: dup
    //   346: new 191	java/lang/StringBuffer
    //   349: dup
    //   350: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   353: ldc_w 616
    //   356: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   359: aload 8
    //   361: invokevirtual 201	java/lang/StringBuffer:append	(Ljava/lang/Object;)Ljava/lang/StringBuffer;
    //   364: ldc_w 541
    //   367: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   370: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   373: invokespecial 617	org/apache/commons/httpclient/CircularRedirectException:<init>	(Ljava/lang/String;)V
    //   376: athrow
    //   377: aload_1
    //   378: invokeinterface 90 1 0
    //   383: aload_0
    //   384: getfield 73	org/apache/commons/httpclient/HttpMethodDirector:params	Lorg/apache/commons/httpclient/params/HttpClientParams;
    //   387: invokevirtual 297	org/apache/commons/httpclient/params/HttpMethodParams:setDefaults	(Lorg/apache/commons/httpclient/params/HttpParams;)V
    //   390: aload 5
    //   392: astore 8
    //   394: goto -140 -> 254
    //   397: astore 13
    //   399: aload 13
    //   401: astore 7
    //   403: new 619	org/apache/commons/httpclient/InvalidRedirectLocationException
    //   406: dup
    //   407: new 191	java/lang/StringBuffer
    //   410: dup
    //   411: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   414: ldc_w 621
    //   417: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   420: aload_3
    //   421: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   424: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   427: aload_3
    //   428: aload 7
    //   430: invokespecial 624	org/apache/commons/httpclient/InvalidRedirectLocationException:<init>	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   433: athrow
    //   434: astore 12
    //   436: iconst_0
    //   437: istore 10
    //   439: goto -383 -> 56
    //   442: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   445: invokeinterface 189 1 0
    //   450: ifeq +49 -> 499
    //   453: getstatic 57	org/apache/commons/httpclient/HttpMethodDirector:LOG	Lorg/apache/commons/logging/Log;
    //   456: new 191	java/lang/StringBuffer
    //   459: dup
    //   460: invokespecial 192	java/lang/StringBuffer:<init>	()V
    //   463: ldc_w 626
    //   466: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   469: aload 4
    //   471: invokevirtual 629	org/apache/commons/httpclient/URI:getEscapedURI	()Ljava/lang/String;
    //   474: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   477: ldc_w 631
    //   480: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   483: aload 8
    //   485: invokevirtual 629	org/apache/commons/httpclient/URI:getEscapedURI	()Ljava/lang/String;
    //   488: invokevirtual 198	java/lang/StringBuffer:append	(Ljava/lang/String;)Ljava/lang/StringBuffer;
    //   491: invokevirtual 204	java/lang/StringBuffer:toString	()Ljava/lang/String;
    //   494: invokeinterface 208 2 0
    //   499: aload_1
    //   500: invokeinterface 152 1 0
    //   505: invokevirtual 634	org/apache/commons/httpclient/auth/AuthState:invalidate	()V
    //   508: iconst_1
    //   509: istore 10
    //   511: goto -455 -> 56
    //   514: astore 9
    //   516: aload 9
    //   518: astore 7
    //   520: goto -117 -> 403
    //   523: astore 6
    //   525: aload 6
    //   527: astore 7
    //   529: goto -126 -> 403
    //
    // Exception table:
    //   from	to	target	type
    //   109	149	397	org/apache/commons/httpclient/URIException
    //   314	328	434	org/apache/commons/httpclient/URIException
    //   149	169	514	org/apache/commons/httpclient/URIException
    //   254	271	514	org/apache/commons/httpclient/URIException
    //   169	254	523	org/apache/commons/httpclient/URIException
    //   377	390	523	org/apache/commons/httpclient/URIException
  }

  private boolean processWWWAuthChallenge(HttpMethod paramHttpMethod)
    throws MalformedChallengeException, AuthenticationException
  {
    AuthState localAuthState = paramHttpMethod.getHostAuthState();
    Map localMap = AuthChallengeParser.parseChallenges(paramHttpMethod.getResponseHeaders("WWW-Authenticate"));
    int i;
    if (localMap.isEmpty())
    {
      LOG.debug("Authentication challenge(s) not found");
      i = 0;
    }
    while (true)
    {
      return i;
      Object localObject = null;
      try
      {
        AuthScheme localAuthScheme = this.authProcessor.processChallenge(localAuthState, localMap);
        localObject = localAuthScheme;
        label63: if (localObject != null)
          break label103;
        label103: i = 0;
      }
      catch (AuthChallengeException localAuthChallengeException)
      {
        if (LOG.isWarnEnabled());
        LOG.warn(localAuthChallengeException.getMessage());
        break label63:
        String str = paramHttpMethod.getParams().getVirtualHost();
        if (str == null)
          str = this.conn.getHost();
        AuthScope localAuthScope = new AuthScope(str, this.conn.getPort(), localObject.getRealm(), localObject.getSchemeName());
        if (LOG.isDebugEnabled())
          LOG.debug("Authentication scope: " + localAuthScope);
        if ((localAuthState.isAuthAttempted()) && (localObject.isComplete()))
        {
          if (promptForCredentials(localObject, paramHttpMethod.getParams(), localAuthScope) == null)
          {
            if (LOG.isInfoEnabled())
              LOG.info("Failure authenticating with " + localAuthScope);
            i = 0;
          }
          i = 1;
        }
        localAuthState.setAuthAttempted(true);
        Credentials localCredentials = this.state.getCredentials(localAuthScope);
        if (localCredentials == null)
          localCredentials = promptForCredentials(localObject, paramHttpMethod.getParams(), localAuthScope);
        if (localCredentials == null)
        {
          if (LOG.isInfoEnabled())
            LOG.info("No credentials available for " + localAuthScope);
          i = 0;
        }
        i = 1;
      }
    }
  }

  private Credentials promptForCredentials(AuthScheme paramAuthScheme, HttpParams paramHttpParams, AuthScope paramAuthScope)
  {
    LOG.debug("Credentials required");
    Object localObject = null;
    CredentialsProvider localCredentialsProvider = (CredentialsProvider)paramHttpParams.getParameter("http.authentication.credential-provider");
    if (localCredentialsProvider != null);
    try
    {
      Credentials localCredentials = localCredentialsProvider.getCredentials(paramAuthScheme, paramAuthScope.getHost(), paramAuthScope.getPort(), false);
      localObject = localCredentials;
      if (localObject != null)
      {
        label56: this.state.setCredentials(paramAuthScope, localObject);
        if (LOG.isDebugEnabled())
          LOG.debug(paramAuthScope + " new credentials given");
      }
      return localObject;
    }
    catch (CredentialsNotAvailableException localCredentialsNotAvailableException)
    {
      LOG.warn(localCredentialsNotAvailableException.getMessage());
      break label56:
      LOG.debug("Credentials provider not available");
    }
  }

  private Credentials promptForProxyCredentials(AuthScheme paramAuthScheme, HttpParams paramHttpParams, AuthScope paramAuthScope)
  {
    LOG.debug("Proxy credentials required");
    Object localObject = null;
    CredentialsProvider localCredentialsProvider = (CredentialsProvider)paramHttpParams.getParameter("http.authentication.credential-provider");
    if (localCredentialsProvider != null);
    try
    {
      Credentials localCredentials = localCredentialsProvider.getCredentials(paramAuthScheme, paramAuthScope.getHost(), paramAuthScope.getPort(), true);
      localObject = localCredentials;
      if (localObject != null)
      {
        label56: this.state.setProxyCredentials(paramAuthScope, localObject);
        if (LOG.isDebugEnabled())
          LOG.debug(paramAuthScope + " new credentials given");
      }
      return localObject;
    }
    catch (CredentialsNotAvailableException localCredentialsNotAvailableException)
    {
      LOG.warn(localCredentialsNotAvailableException.getMessage());
      break label56:
      LOG.debug("Proxy credentials provider not available");
    }
  }

  public void executeMethod(HttpMethod paramHttpMethod)
    throws IOException, HttpException
  {
    if (paramHttpMethod == null)
      throw new IllegalArgumentException("Method may not be null");
    this.hostConfiguration.getParams().setDefaults(this.params);
    paramHttpMethod.getParams().setDefaults(this.hostConfiguration.getParams());
    Collection localCollection = (Collection)this.hostConfiguration.getParams().getParameter("http.default-headers");
    if (localCollection != null)
    {
      Iterator localIterator = localCollection.iterator();
      while (localIterator.hasNext())
        paramHttpMethod.addRequestHeader((Header)localIterator.next());
    }
    while (true)
    {
      int i;
      int j;
      int k;
      try
      {
        i = this.params.getIntParameter("http.protocol.max-redirects", 100);
        j = 0;
        if ((this.conn != null) && (!(this.hostConfiguration.hostEquals(this.conn))))
        {
          this.conn.setLocked(false);
          this.conn.releaseConnection();
          this.conn = null;
        }
        if (this.conn == null)
        {
          this.conn = this.connectionManager.getConnectionWithTimeout(this.hostConfiguration, this.params.getConnectionManagerTimeout());
          this.conn.setLocked(true);
          if ((this.params.isAuthenticationPreemptive()) || (this.state.isAuthenticationPreemptive()))
          {
            LOG.debug("Preemptively sending default basic credentials");
            paramHttpMethod.getHostAuthState().setPreemptive();
            paramHttpMethod.getHostAuthState().setAuthAttempted(true);
            if ((this.conn.isProxied()) && (!(this.conn.isSecure())))
            {
              paramHttpMethod.getProxyAuthState().setPreemptive();
              paramHttpMethod.getProxyAuthState().setAuthAttempted(true);
            }
          }
        }
        authenticate(paramHttpMethod);
        executeWithRetry(paramHttpMethod);
        if (this.connectMethod != null)
        {
          fakeResponse(paramHttpMethod);
          return;
        }
        throw new RedirectException("Maximum redirects (" + i + ") exceeded");
      }
      finally
      {
        if (this.conn != null)
          this.conn.setLocked(false);
        if ((((this.releaseConnection) || (paramHttpMethod.getResponseBodyAsStream() == null))) && (this.conn != null))
          this.conn.releaseConnection();
      }
      if (LOG.isDebugEnabled())
        LOG.debug("Execute redirect " + j + " of " + i);
      if ((isAuthenticationNeeded(paramHttpMethod)) && (processAuthenticationResponse(paramHttpMethod)))
      {
        LOG.debug("Retry authentication");
        k = 1;
      }
      if (k == 0)
        continue;
      if (paramHttpMethod.getResponseBodyAsStream() == null)
        continue;
      paramHttpMethod.getResponseBodyAsStream().close();
    }
  }

  public HttpConnectionManager getConnectionManager()
  {
    return this.connectionManager;
  }

  public HostConfiguration getHostConfiguration()
  {
    return this.hostConfiguration;
  }

  public HttpParams getParams()
  {
    return this.params;
  }

  public HttpState getState()
  {
    return this.state;
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     org.apache.commons.httpclient.HttpMethodDirector
 * JD-Core Version:    0.5.3
 */